
package br.com.romerito.gui.logo;

import br.com.romerito.app.MidletApp;
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author Romerito Campos
 */
public class Help extends Canvas implements CommandListener {

    private Image image;
    private Command exit;
    private boolean detail = false;

    public Help() {
        setFullScreenMode(true);

        try {
            image = Image.createImage("/ajuda.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        exit = new Command("sair", Command.BACK, 1);
        addCommand(exit);
        setCommandListener(this);

    }


    protected void keyPressed(int keyCode) {
        super.keyPressed(keyCode);

        if(getGameAction(keyCode) == DOWN){
            detail = true;
            repaint();
        }

        if(getGameAction(keyCode)==UP){
            detail = false;
            repaint();
        }
    }


    protected void paint(Graphics g) {
        g.setColor(0x00ffffff);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(0x00000000);
        g.drawString("AJUDA", getWidth() / 2, 0, Graphics.TOP | Graphics.HCENTER);

        int x = (getWidth() - image.getWidth());
        System.out.println(x-image.getWidth()/2);
        int y = g.getFont().getHeight() + 1;
        g.drawImage(image, x, y, Graphics.TOP | Graphics.HCENTER);


        if(!detail){
            g.drawString("1 - pf <distancia>", 2, y+image.getHeight(), Graphics.TOP | Graphics.LEFT);
            g.drawString("2 - pt <distancia>", 2, 2*y+image.getHeight(), Graphics.TOP | Graphics.LEFT);
            g.drawString("3 - pe <grau>", 2, 3*y+image.getHeight(), Graphics.TOP | Graphics.LEFT);
            g.drawString("4 - pd <grau>", 2, 4*y+image.getHeight(), Graphics.TOP | Graphics.LEFT);
            g.drawString("5 - Executar", 2, 5*y+image.getHeight(), Graphics.TOP | Graphics.LEFT);
            g.drawString("v", getWidth()-6, getHeight()-g.getFont().getHeight(), Graphics.TOP | Graphics.LEFT);
        }else{
            g.drawString("pf para frente", 2, y+image.getHeight(),Graphics.TOP | Graphics.LEFT);
            g.drawString("pt para trás", 2, 2*y+image.getHeight(),Graphics.TOP | Graphics.LEFT);
            g.drawString("pe para esquerda", 2, 3*y+image.getHeight(),Graphics.TOP | Graphics.LEFT);
            g.drawString("pd para direita", 2, 4*y+image.getHeight(),Graphics.TOP | Graphics.LEFT);
            g.drawString("x", getWidth()-6, getHeight()-g.getFont().getHeight(), Graphics.TOP | Graphics.LEFT);
        }

    }

    public void commandAction(Command cmnd, Displayable dsplbl) {
        if(exit == cmnd){
            MidletApp.app.showMenu();
        }

    }


}

